package com.h4313.ghome.ui.animations;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.RadialGradient;
import android.graphics.drawable.GradientDrawable;
import android.view.View;

public class NewModuleBackgroundAnimation implements AnimatorListener {

	private final View mAnimatedView;
	
	private Integer white = Color.rgb(0xff, 0xff, 0xff);
	private Integer green = Color.rgb(0x69, 0xab, 0x3c);
	private GradientDrawable mGradient;
	private static final int duration = 150;
	
	public NewModuleBackgroundAnimation(View animatedView) {
		
		mAnimatedView = animatedView;
	}

	public void animate() {
		ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), white, green);
		colorAnimation.setDuration(duration);
		colorAnimation.setStartDelay(1000);
		colorAnimation.addUpdateListener(new AnimatorUpdateListener() {

		    @Override
		    public void onAnimationUpdate(ValueAnimator animator) {
		    	mAnimatedView.setBackgroundColor((Integer)animator.getAnimatedValue());
		    }

		});
		
		colorAnimation.addListener(this);
		colorAnimation.start();
	}

	@Override
	public void onAnimationCancel(Animator animation) {
	}

	@Override
	public void onAnimationEnd(Animator animation) {
		ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), green, white);
		colorAnimation.setDuration(duration);
		colorAnimation.addUpdateListener(new AnimatorUpdateListener() {

		    @Override
		    public void onAnimationUpdate(ValueAnimator animator) {
		    	mAnimatedView.setBackgroundColor((Integer)animator.getAnimatedValue());
		    }
		});
		colorAnimation.start();
	}

	@Override
	public void onAnimationRepeat(Animator animation) {
	}

	@Override
	public void onAnimationStart(Animator animation) {
	}
	
	
}
